package com.ponhu.ea2.dto;

import com.ponhu.ea2.annotations.EnableColumnChangeLog;
import com.ponhu.ea2.annotations.OperationRecordId;
import com.ponhu.ea2.constants.CommonConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;

import javax.annotation.PostConstruct;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

import static com.ponhu.ea2.enums.InventoryAppraisalEnum.*;

/**
 * <p>
 * 货品中检结果表
 * </p>
 *
 * @author ${author}
 * @since 2021-10-19
 */
@Data
@Accessors(chain = true)
@ApiModel(value = "中检溯源码-数据传输模型 ")
public class PhInventoryAppraisalDto implements Serializable {

    @ApiModelProperty(value = "货品ID", hidden = true)
    @OperationRecordId(businessTable = CommonConstant.BUSINESS_TYPE_INVENTORY)
    private Long inventoryId;

    @ApiModelProperty(value = "货品编码", required = true)
    @NotEmpty(message = "货品编码不能为空")
    private String inventoryCode;

    @ApiModelProperty(value = "鉴定机构", required = true)
    @NotEmpty(message = "鉴定机构不能为空")
    @EnableColumnChangeLog(columnDesc = "鉴定机构")
    private String appraisalOrg;

    @ApiModelProperty(value = "鉴定时间", required = true)
    @NotNull(message = "鉴定时间不能为空")
    @EnableColumnChangeLog(columnDesc = "鉴定时间")
    private LocalDateTime appraisalTime;

    @NotNull(message = "中检状态不能为空")
    @Max(value = 5, message = "中检状态只能是：1未中检，2中检已通过，3中检未通过, 5不符合挂签标准")
    @Min(value = 1, message = "中检状态只能是：1未中检，2中检已通过，3中检未通过, 5不符合挂签标准")
    @ApiModelProperty(value = "中检状态：1未中检，2中检已通过，3中检未通过, 5不符合挂签标准", required = true)
    private Integer isDoneCcic;

    @ApiModelProperty(value = "中检溯源码")
    @EnableColumnChangeLog(columnDesc = "中检溯源码")
    private String sourceCode;

    @ApiModelProperty(value = "中检状态", hidden = true)
    @EnableColumnChangeLog(columnDesc = "中检状态")
    private String isDoneCcicStr;

    public PhInventoryAppraisalDto initIsDoneCcicStr() {
        if (StringUtils.isEmpty(appraisalOrg) && isDoneCcic == isDoneCcic_1.getCode())
            isDoneCcicStr = isDoneCcic_1.getName();
        if (StringUtils.isNotEmpty(appraisalOrg) && isDoneCcic == isDoneCcic_1.getCode())
            isDoneCcicStr = isDoneCcic_4.getName();
        if (isDoneCcic == isDoneCcic_2.getCode())
            isDoneCcicStr = isDoneCcic_2.getName();
        if (isDoneCcic == isDoneCcic_3.getCode())
            isDoneCcicStr = isDoneCcic_3.getName();
        if (isDoneCcic == isDoneCcic_5.getCode())
            isDoneCcicStr = isDoneCcic_5.getName();
        return this;
    }

}